import 'package:flutter_yn_goods/user/app_user_manager.dart';
import 'package:flutter_yn_goods/utils/loading/loading_utils.dart';
import 'package:get/get.dart';

import 'modify_name_state.dart';

class ModifyNameLogic extends GetxController {
  final ModifyNameState state = ModifyNameState();

  String initName = "";
  @override
  void onInit() {
    super.onInit();
    initName = AppUserManager().user.value?.nickname??"";
    state.textEditingController.text = initName;
  }
  void saveName() async {
    String name = state.textEditingController.text;
    if(initName==name){
      Get.back();
    }else{
      var response = await AppUserManager().saveUserInfo(nickname: name,showLoading: true);
      if(response.isSuccess){
        Get.back();
      }else{
        LoadingUtils.showToast(response.codeAndMsg);
      }
    }
  }
}
